use "$temp/psid_home_eq", clear
merge 1:1 uniqid year using "$data/PSID/income/psid_income", keep(match) nogen
merge 1:1 uniqid year using "$temp/psid_weights", keep(match) nogen
drop deflator sex relate_
ren weight weight_
ren home_eq home_eq_
ren inc_lab_ inc_


reshape wide home_eq_ age_ inc_ weight_, i(uniqid) j(year)

keep if age_2001>=25 & age_2001>=45 //reasonable parent age range

egen inc_pre = rowmean(inc_2001 inc_2002 inc_2003 inc_2004 inc_2005 inc_2006 inc_2007)
egen home_eq_pre = rowmean(home_eq_2007)
egen home_eq_post = rowmean(home_eq_2013)


gen home_rat = home_eq_post / home_eq_pre
xtile inc_pre_dec = inc_pre, nq(10)
drop if home_eq_pre<= 0 | home_eq_pre == .

qui{
forval i = 1/10{
	su home_eq_pre [w=weight_2001] if inc_pre_dec == `i'
	local eq_pre = `r(mean)'
	
	su home_eq_post [w=weight_2001] if inc_pre_dec == `i'
	local eq_post = `r(mean)'
	
	
	su home_rat [w=weight_2001] if inc_pre_dec == `i', d
	
	local res1 = `r(mean)'
	local res2 = `r(p50)'
	
	local res3 = `eq_post' / `eq_pre'
	
	noi di "`res1' || `res2' || `res3'"
	
	
	local home_shock_`i' = `res3'
	
}
}


clear
set obs 20
gen home_shock = .
forval i = 1/10{
	local r1 = `i' * 2 - 1
	local r2 = `i' * 2
	
	replace home_shock = `home_shock_`i'' in `r1'
	replace home_shock = `home_shock_`i'' in `r2'
}


export delimited "$dir/model/utilities/rec_home_shocks.csv", novarn replace








